;;******************************************************************************
;; Project Name: Regulatory Knowledge Based System for Sennheiser 
;; Team Members: 
;; Batch: MTech KE24
;; Version: 1.0
;; Date Created: 09 Mar 2013
;; Date Updated: 
;;******************************************************************************

;;******************************************************************************
;; DEFMODULE MAIN
;;******************************************************************************
;;
(defmodule MAIN (export ?ALL))

;;******************************************************************************
;; DEFGLOBALS
;;******************************************************************************
;;
(defglobal 
	?*product_name* = ""
)

;;******************************************************************************
;; DEFFUNCTIONS
;;******************************************************************************
;; CheckOptions
(deffunction MAIN::CheckOptions (?min ?max ?option)
	(if (or (eq (str-length ?option) 0)
		(not (integerp (string-to-field ?option)))
			(< (string-to-field ?option) ?min)
			(> (string-to-field ?option) ?max))
		then TRUE
    else FALSE)
)

;; ConvertProductMenu
(deffunction MAIN::ConvertProductMenu (?option)
	(switch ?option
		(case 1 then (bind ?return-value ProductHeadphone))
		(case 2 then (bind ?return-value ProductOthers))
		(case 0 then (bind ?return-value Exit_SRKBS))
	)
	(return ?return-value)
)
	 
;;******************************************************************************
;; DEFTEMPLATE
;;******************************************************************************
;;

;;******************************************************************************
;; DEFRULE
;;****************************************************************************** 
;;
;; Initialize Program
(defrule MAIN::Init
	?f <- (initial-fact)
=>
	(retract ?f)
	(assert (phase RKBS_Start))
)

;; 
(defrule MAIN::RKBS_Start
	?f <- (phase RKBS_Start)
=>
	(retract ?f)
	(printout t crlf 
	"Regulatory Knowledge Based System" crlf
	"=================================" crlf
	crlf
	"Please enter Project/Product name (press the RETURN key for Testing): ")
	(bind ?*product_name* (readline))
	(if (eq (str-length ?*product_name*) 0)
		then (bind ?*product_name* "Testing")
	)
	(printout t crlf "Ready to prepare Regulatory Requirements for " ?*product_name* crlf)
	(assert (phase RKBS_Main))
)	
	
;;	
(defrule MAIN::RKBS_Main
	(declare (auto-focus TRUE))
	?f <- (phase RKBS_Main)
=>
	(retract ?f)
	(bind ?min 0)
	(bind ?max 2)
	(printout t crlf
		"========================================" crlf
		" Product Options 	    				 " crlf
		"========================================" crlf
		crlf
		"1. Headphone" crlf
		"2. Others" crlf
		"0. Exit" crlf
		crlf
		"Please select an option (" ?min "-" ?max "): "
	)
	(bind ?option (readline))
	(if (CheckOptions ?min ?max ?option)
		then (and (printout t crlf "Invalid Options " ?option crlf)
            (assert (phase RKBS_Main)))
		else (and (bind ?option (ConvertProductMenu (string-to-field ?option)))
            (assert (phase ?option)))
	)
)

;; ProductOthers
(defrule MAIN::ProductOthers
	(declare (auto-focus TRUE))
	?f <- (phase ProductOthers)
=>
	(retract ?f)
	(printout t crlf
		"Not implemented yet." crlf
		crlf
	)
	(assert (stop))
	(assert (quit))
)

;;
(defrule MAIN::Exit_SRKBS
	(declare (auto-focus TRUE))
	?f <- (phase Exit_SRKBS)
=>
	(retract ?f)
	(printout t crlf "Program Exit. " crlf)
	(assert (stop))
	(assert (quit))
)

;;******************************************************************************
;; DEFMODULE REGULATORY
;;******************************************************************************
;;
(defmodule REGULATORY (import MAIN ?ALL))

;; ConvertHeadphoneMenu
(deffunction REGULATORY::ConvertHeadphoneMenu (?option)
	(switch ?option
		(case 1 then (bind ?return-value HeadphonePassive))
		(case 2 then (bind ?return-value HeadphoneActive))
	)
	(return ?return-value)
)

;; ConvertHeadphoneActiveMenu
(deffunction REGULATORY::ConvertHeadphoneActiveMenu (?option)
	(switch ?option
		(case 1 then (bind ?return-value HeadphoneActive_Wireless))
		(case 2 then (bind ?return-value HeadphoneActive_Wired))		
	)
	(return ?return-value)
)

;; ConvertHeadphoneActiveWirelessMenu
(deffunction REGULATORY::ConvertHeadphoneActiveWirelessMenu (?option)
	(switch ?option
		(case 1 then (bind ?return-value HeadphoneActiveWireless_Bluetooth))
		(case 2 then (bind ?return-value HeadphoneActiveWireless_Dect))
		(case 3 then (bind ?return-value HeadphoneActiveWireless_Wifi))
		(case 4 then (bind ?return-value HeadphoneActiveWireless_Other))
	)
	(return ?return-value)
)

;; ConvertHeadphoneActiveWiredMenu
(deffunction REGULATORY::ConvertHeadphoneActiveWiredMenu (?option)
	(switch ?option
		(case 1 then (bind ?return-value HeadphoneActiveWired_Battery))
		(case 2 then (bind ?return-value HeadphoneActiveWired_Main))
	)
	(return ?return-value)
)

;; ConvertHeadphoneActiveWiredBatteryMenu
(deffunction REGULATORY::ConvertHeadphoneActiveWiredBatteryMenu (?option)
	(switch ?option
		(case 1 then (bind ?return-value HeadphoneActiveWiredBattery_Primary))
		(case 2 then (bind ?return-value HeadphoneActiveWiredBattery_Secondary))
	)
	(return ?return-value)
)

;; ConvertHeadphoneActiveWiredBatteryPrimaryMenu
(deffunction REGULATORY::ConvertHeadphoneActiveWiredBatteryPrimaryMenu (?option)
	(switch ?option
		(case 1 then (bind ?return-value HeadphoneActiveWiredBatteryPrimary_EU))
		(case 2 then (bind ?return-value HeadphoneActiveWiredBatteryPrimary_USA))
		(case 3 then (bind ?return-value HeadphoneActiveWiredBatteryPrimary_CA))
		(case 4 then (bind ?return-value HeadphoneActiveWiredBatteryPrimary_AUS_NZ))
		(case 5 then (bind ?return-value HeadphoneActiveWiredBatteryPrimary_Other))
	)
	(return ?return-value)
)

;; ConvertHeadphoneActiveWiredBatteryPrimaryUSAMenu
(deffunction REGULATORY::ConvertHeadphoneActiveWiredBatteryPrimaryUSAMenu (?option)
	(switch ?option
		(case 1 then (bind ?return-value ConvertHeadphoneActiveWiredBatteryPrimaryUSA_FreqH9))
		(case 2 then (bind ?return-value ConvertHeadphoneActiveWiredBatteryPrimaryUSA_FreqL9))
	)
	(return ?return-value)
)

;; ConvertHeadphoneActiveWiredBatteryPrimaryUSAFreqL9Menu
(deffunction REGULATORY::ConvertHeadphoneActiveWiredBatteryPrimaryUSAFreqL9Menu (?option)
	(switch ?option
		(case 1 then (bind ?return-value ConvertHeadphoneActiveWiredBatteryPrimaryUSA_FreqH9))
		(case 2 then (bind ?return-value ConvertHeadphoneActiveWiredBatteryPrimaryUSAFreq9L_GenL17))
	)
	(return ?return-value)
)

;; ConvertHeadphoneActiveWiredBatteryPrimaryUSAFreq9LGenL17Menu
(deffunction REGULATORY::ConvertHeadphoneActiveWiredBatteryPrimaryUSAFreq9LGenL17Menu (?option)
	(switch ?option
		(case 1 then (bind ?return-value ConvertHeadphoneActiveWiredBatteryPrimaryUSA_FreqH9))
		(case 2 then (bind ?return-value NoFCCDeclaration))
	)
	(return ?return-value)
)

;; ConvertHeadphoneActiveWiredBatteryPrimaryCAMenu
(deffunction REGULATORY::ConvertHeadphoneActiveWiredBatteryPrimaryCAMenu (?option)
	(switch ?option
		(case 1 then (bind ?return-value ConvertHeadphoneActiveWiredBatteryPrimaryCA_FreqH9))
		(case 2 then (bind ?return-value ConvertHeadphoneActiveWiredBatteryPrimaryCA_FreqL9))
	)
	(return ?return-value)
)

;; ConvertHeadphoneActiveWiredBatteryPrimaryCAFreqL9Menu
(deffunction REGULATORY::ConvertHeadphoneActiveWiredBatteryPrimaryCAFreqL9Menu (?option)
	(switch ?option
		(case 1 then (bind ?return-value ConvertHeadphoneActiveWiredBatteryPrimaryCA_FreqH9))
		(case 2 then (bind ?return-value ConvertHeadphoneActiveWiredBatteryPrimaryCAFreq9L_GenL17))
	)
	(return ?return-value)
)

;; ConvertHeadphoneActiveWiredBatteryPrimaryCAFreq9LGenL17Menu
(deffunction REGULATORY::ConvertHeadphoneActiveWiredBatteryPrimaryCAFreq9LGenL17Menu (?option)
	(switch ?option
		(case 1 then (bind ?return-value ConvertHeadphoneActiveWiredBatteryPrimaryCA_FreqH9))
		(case 2 then (bind ?return-value NoTest))
	)
	(return ?return-value)
)

;; ConvertHeadphoneActiveWiredBatterySecondaryMenu
(deffunction REGULATORY::ConvertHeadphoneActiveWiredBatterySecondaryMenu (?option)
	(switch ?option
		(case 1 then (bind ?return-value ConvertHeadphoneActiveWiredBatterySecondary_Nimh))
		(case 2 then (bind ?return-value ConvertHeadphoneActiveWiredBatterySecondary_Li))
	)
	(return ?return-value)
)

;; ConvertHeadphoneActiveWiredBatterySecondaryNimhMenu
(deffunction REGULATORY::ConvertHeadphoneActiveWiredBatterySecondaryNimhMenu (?option)
	(switch ?option
		(case 1 then (bind ?return-value NotImplementedYet))
		(case 2 then (bind ?return-value NotImplementedYet))
	)
	(return ?return-value)
)

;; ConvertHeadphoneActiveWiredBatterySecondaryLiMenu
(deffunction REGULATORY::ConvertHeadphoneActiveWiredBatterySecondaryLiMenu (?option)
	(switch ?option
		(case 1 then (bind ?return-value NotImplementedYet))
		(case 2 then (bind ?return-value NotImplementedYet))
	)
	(return ?return-value)
)

;;******************************************************************************
;; Deftemplates
;;******************************************************************************
;; TechnicalRequirements (FORM_08_51)
(deftemplate TechnicalRequirements

)

;; CertificationPlan Template (FORM_08_52)
(deftemplate CertificationPlan

)

;; ProductHeadphone
(defrule REGULATORY::ProductHeadphone
	(declare (auto-focus TRUE))
	?f <- (phase ProductHeadphone)
=>
	(retract ?f)
	(bind ?min 1)
	(bind ?max 2)
	(printout t crlf
		"========================================" crlf
		" Select Headphone Options 				 " crlf
		"========================================" crlf
		crlf
		"1. Passive" crlf
		"2. Active" crlf
		crlf
		"Please select an option (" ?min "-" ?max "): "
	)
	(bind ?option (readline))
	(if (CheckOptions ?min ?max ?option)
		then (and (printout t crlf "Invalid Options " ?option crlf)
            (assert (phase ProductHeadphone)))
		else (and (bind ?option (ConvertHeadphoneMenu (string-to-field ?option)))
            (assert (phase ?option)))
	)
)

;; HeadphonePassive
(defrule REGULATORY::HeadphonePassive
	(declare (auto-focus TRUE))
	?f <- (phase HeadphonePassive)
=>
	(retract ?f)
	(printout t crlf
		"Not implemented yet." crlf
		crlf
	)
	(assert (stop))
	(assert (quit))
)

;; NotImplementedYet
(defrule REGULATORY::NotImplementedYet
	(declare (auto-focus TRUE))
	?f <- (phase NotImplementedYet)
=>
	(retract ?f)
	(printout t crlf
		"Not implemented yet." crlf
		crlf
	)
	(assert (stop))
	(assert (quit))
)

;; HeadphoneActive
(defrule REGULATORY::HeadphoneActive
	(declare (auto-focus TRUE))
	?f <- (phase HeadphoneActive)
=>
	(retract ?f)
	(bind ?min 1)
	(bind ?max 2)
	(printout t crlf
		"========================================" crlf
		" Select Headphone Active Options 		 " crlf
		"========================================" crlf
		crlf
		"1. Wireless (Intentional)" crlf
		"2. Wired (Unintentional)" crlf
		crlf
		"Please select an option (" ?min "-" ?max "): "
	)
	(bind ?option (readline))
	(if (CheckOptions ?min ?max ?option)
		then (and (printout t crlf "Invalid Options " ?option crlf)
            (assert (phase HeadphoneActive)))
		else (and (bind ?option (ConvertHeadphoneActiveMenu (string-to-field ?option)))
            (assert (phase ?option)))
	)
)

;; HeadphoneActive_Wireless
(defrule HeadphoneActive_Wireless
	(declare (auto-focus TRUE))
	?f <- (phase HeadphoneActive_Wireless)
=>
	(retract ?f)
	(bind ?min 1)
	(bind ?max 4)
	(printout t crlf
		"================================================" crlf
		" Select Headphone Active Wireless Options 		 " crlf
		"================================================" crlf
		crlf
		"1. Bluetooth" crlf
		"2. Dect" crlf
		"3. Wifi" crlf
		"4. Other" crlf
		crlf
		"Please select an option (" ?min "-" ?max "): "
	)
	(bind ?option (readline))
	(if (CheckOptions ?min ?max ?option)
		then (and (printout t crlf "Invalid Options " ?option crlf)
            (assert (phase HeadphoneActive_Wireless)))
		else (and (bind ?option (ConvertHeadphoneActiveWirelessMenu (string-to-field ?option)))
            (assert (phase ?option)))
	)
)

;; HeadphoneActiveWireless_Bluetooth
(defrule REGULATORY::HeadphoneActiveWireless_Bluetooth
	(declare (auto-focus TRUE))
	?f <- (phase HeadphoneActiveWireless_Bluetooth)
=>
	(retract ?f)
	(printout t crlf
		"Not implemented yet." crlf
		crlf
	)
	(assert (stop))
	(assert (quit))
)

;; HeadphoneActiveWireless_Dect
(defrule REGULATORY::HeadphoneActiveWireless_Dect
	(declare (auto-focus TRUE))
	?f <- (phase HeadphoneActiveWireless_Dect)
=>
	(retract ?f)
	(printout t crlf
		"Not implemented yet." crlf
		crlf
	)
	(assert (stop))
	(assert (quit))
)

;; HeadphoneActiveWireless_Wifi
(defrule REGULATORY::HeadphoneActiveWireless_Wifi
	(declare (auto-focus TRUE))
	?f <- (phase HeadphoneActiveWireless_Wifi)
=>
	(retract ?f)
	(printout t crlf
		"Not implemented yet." crlf
		crlf
	)
	(assert (stop))
	(assert (quit))
)

;; HeadphoneActiveWireless_Other
(defrule REGULATORY::HeadphoneActiveWireless_Other
	(declare (auto-focus TRUE))
	?f <- (phase HeadphoneActiveWireless_Other)
=>
	(retract ?f)
	(printout t crlf
		"Not implemented yet." crlf
		crlf
	)
	(assert (stop))
	(assert (quit))
)

;; HeadphoneActive_Wired
(defrule HeadphoneActive_Wired
	(declare (auto-focus TRUE))
	?f <- (phase HeadphoneActive_Wired)
=>
	(retract ?f)
	(bind ?min 1)
	(bind ?max 2)
	(printout t crlf
		"================================================" crlf
		" Select Headphone Active Wireless Options 		 " crlf
		"================================================" crlf
		crlf
		"1. Battery" crlf
		"2. Main" crlf
		crlf
		"Please select an option (" ?min "-" ?max "): "
	)
	(bind ?option (readline))
	(if (CheckOptions ?min ?max ?option)
		then (and (printout t crlf "Invalid Options " ?option crlf)
            (assert (phase HeadphoneActive_Wired)))
		else (and (bind ?option (ConvertHeadphoneActiveWiredMenu (string-to-field ?option)))
            (assert (phase ?option)))
	)
)

;; HeadphoneActiveWired_Main
(defrule HeadphoneActiveWired_Main
	(declare (auto-focus TRUE))
	?f <- (phase HeadphoneActiveWired_Main)
=>
	(retract ?f)
	(printout t crlf
		"Please check with Regulatory Manager." crlf
		crlf
	)
	(assert (stop))
	(assert (quit))
)

;; HeadphoneActiveWired_Battery
(defrule HeadphoneActiveWired_Battery
	(declare (auto-focus TRUE))
	?f <- (phase HeadphoneActiveWired_Battery)
=>
	(retract ?f)
	(bind ?min 1)
	(bind ?max 2)
	(printout t crlf
		"================================================" crlf
		" Select Headphone Active Wired Battery Options  " crlf
		"================================================" crlf
		crlf
		"1. Primary" crlf
		"2. Secondary" crlf
		crlf
		"Please select an option (" ?min "-" ?max "): "
	)
	(bind ?option (readline))
	(if (CheckOptions ?min ?max ?option)
		then (and (printout t crlf "Invalid Options " ?option crlf)
            (assert (phase HeadphoneActiveWired_Battery)))
		else (and (bind ?option (ConvertHeadphoneActiveWiredBatteryMenu (string-to-field ?option)))
            (assert (phase ?option)))
	)
)

;; HeadphoneActiveWiredBattery_Primary
(defrule HeadphoneActiveWiredBattery_Primary
	(declare (auto-focus TRUE))
	?f <- (phase HeadphoneActiveWiredBattery_Primary)
=>
	(retract ?f)
	(bind ?min 1)
	(bind ?max 5)
	(printout t crlf
		"========================================================" crlf
		" Select Headphone Active Wired Battery Primary Options  " crlf
		"========================================================" crlf
		crlf
		"1. EU" crlf
		"2. USA" crlf
		"3. CA" crlf
		"4. Australia/NZ" crlf
		"5. Others" crlf
		crlf
		"Please select an option (" ?min "-" ?max "): "
	)
	(bind ?option (readline))
	(if (CheckOptions ?min ?max ?option)
		then (and (printout t crlf "Invalid Options " ?option crlf)
            (assert (phase HeadphoneActiveWiredBattery_Primary)))
		else (and (bind ?option (ConvertHeadphoneActiveWiredBatteryPrimaryMenu (string-to-field ?option)))
            (assert (phase ?option)))
	)
)

;; HeadphoneActiveWiredBatteryPrimary_Other
(defrule HeadphoneActiveWiredBatteryPrimary_Other
	(declare (auto-focus TRUE))
	?f <- (phase HeadphoneActiveWiredBatteryPrimary_Other)
=>
	(retract ?f)
	(printout t crlf
		"No declaration required." crlf
		crlf
	)
	(assert (stop))
	(assert (quit))
)

;; NoFCCDeclaration
(defrule NoFCCDeclaration
	(declare (auto-focus TRUE))
	?f <- (phase NoFCCDeclaration)
=>
	(retract ?f)
	(printout t crlf
		"No FCC declaration required." crlf
		crlf
	)
	(assert (stop))
	(assert (quit))
)

;; NoTest
(defrule NoTest
	(declare (auto-focus TRUE))
	?f <- (phase NoTest)
=>
	(retract ?f)
	(printout t crlf
		"No Test." crlf
		crlf
	)
	(assert (stop))
	(assert (quit))
)

;; HeadphoneActiveWiredBatteryPrimary_AUS_NZ
(defrule HeadphoneActiveWiredBatteryPrimary_AUS_NZ
	(declare (auto-focus TRUE))
	?f <- (phase HeadphoneActiveWiredBatteryPrimary_AUS_NZ)
=>
	(retract ?f)
	(printout t crlf
		"Applicable Requirement(s): C-Tick" crlf
		"Applicable Standard(s): AS/NZS CISPR 22:2009/Amdt 1:2010" crlf
		crlf
	)
	(assert (stop))
	(assert (quit))
)

;; HeadphoneActiveWiredBatteryPrimary_EU
(defrule HeadphoneActiveWiredBatteryPrimary_EU
	(declare (auto-focus TRUE))
	?f <- (phase HeadphoneActiveWiredBatteryPrimary_EU)
=>
	(retract ?f)
	(printout t crlf
		"Applicable Requirement(s): EMC Directive (2004/108/EC)" crlf
		"Applicable Standard(s):-" crlf
		"    AV Standards" crlf
		"    ------------" crlf
		"    EN55013-Emission" crlf
		"    EN55020-Immunity" crlf
		"    ITE Standards" crlf
		"    -------------" crlf
		"    EN55022-Emission" crlf
		"    EN55024-Immunity" crlf
		crlf
	)
	(assert (stop))
	(assert (quit))
)

;; HeadphoneActiveWiredBatteryPrimary_USA
(defrule HeadphoneActiveWiredBatteryPrimary_USA
	(declare (auto-focus TRUE))
	?f <- (phase HeadphoneActiveWiredBatteryPrimary_USA)
=>
	(retract ?f)
	(bind ?min 1)
	(bind ?max 2)
	(printout t crlf
		"============================================================" crlf
		" Select Headphone Active Wired Battery Primary USA Options  " crlf
		"============================================================" crlf
		crlf
		"1. Clock Freq > 9KHZ" crlf
		"2. Clock Freq < 9KHZ" crlf
		crlf
		"Please select an option (" ?min "-" ?max "): "
	)
	(bind ?option (readline))
	(if (CheckOptions ?min ?max ?option)
		then (and (printout t crlf "Invalid Options " ?option crlf)
            (assert (phase HeadphoneActiveWiredBatteryPrimary_USA)))
		else (and (bind ?option (ConvertHeadphoneActiveWiredBatteryPrimaryUSAMenu (string-to-field ?option)))
            (assert (phase ?option)))
	)
)

;; ConvertHeadphoneActiveWiredBatteryPrimaryUSA_FreqH9
(defrule ConvertHeadphoneActiveWiredBatteryPrimaryUSA_FreqH9
	(declare (auto-focus TRUE))
	?f <- (phase ConvertHeadphoneActiveWiredBatteryPrimaryUSA_FreqH9)
=>
	(retract ?f)
	(printout t crlf
		"Applicable Requirement(s): FCC part 15, Subpart b, Unintentional radiator" crlf
		"Applicable Standard(s): " crlf
		"----------------------- " crlf
		"FCC Part 15. 107" crlf
		"FCC Part 15. 109" crlf
		crlf
	)
	(assert (stop))
	(assert (quit))
)

;; ConvertHeadphoneActiveWiredBatteryPrimaryUSA_FreqL9
(defrule ConvertHeadphoneActiveWiredBatteryPrimaryUSA_FreqL9
	(declare (auto-focus TRUE))
	?f <- (phase ConvertHeadphoneActiveWiredBatteryPrimaryUSA_FreqL9)
=>
	(retract ?f)
	(bind ?min 1)
	(bind ?max 2)
	(printout t crlf
		"=============================================================================" crlf
		" Select Headphone Active Wired Battery Primary USA ClockFreq < 9KHZ Options  " crlf
		"=============================================================================" crlf
		crlf
		"1. Generated used > 1.705 mHz" crlf
		"2. Generated used < 1.705 mHz" crlf
		crlf
		"Please select an option (" ?min "-" ?max "): "
	)
	(bind ?option (readline))
	(if (CheckOptions ?min ?max ?option)
		then (and (printout t crlf "Invalid Options " ?option crlf)
            (assert (phase ConvertHeadphoneActiveWiredBatteryPrimaryUSA_FreqL9)))
		else (and (bind ?option (ConvertHeadphoneActiveWiredBatteryPrimaryUSAFreqL9Menu (string-to-field ?option)))
            (assert (phase ?option)))
	)
)

;; ConvertHeadphoneActiveWiredBatteryPrimaryUSAFreq9L_GenL17
(defrule ConvertHeadphoneActiveWiredBatteryPrimaryUSAFreq9L_GenL17
	(declare (auto-focus TRUE))
	?f <- (phase ConvertHeadphoneActiveWiredBatteryPrimaryUSAFreq9L_GenL17)
=>
	(retract ?f)
	(bind ?min 1)
	(bind ?max 2)
	(printout t crlf
		"======================================================================================================" crlf
		" Select Headphone Active Wired Battery Primary USA ClockFreq < 9KHZ Generated used <1.705mHz Options  " crlf
		"======================================================================================================" crlf
		crlf
		"1. Directly connected to mains" crlf
		"2. Not directly connected to mains" crlf
		crlf
		"Please select an option (" ?min "-" ?max "): "
	)
	(bind ?option (readline))
	(if (CheckOptions ?min ?max ?option)
		then (and (printout t crlf "Invalid Options " ?option crlf)
            (assert (phase ConvertHeadphoneActiveWiredBatteryPrimaryUSAFreq9L_GenL17)))
		else (and (bind ?option (ConvertHeadphoneActiveWiredBatteryPrimaryUSAFreq9LGenL17Menu (string-to-field ?option)))
            (assert (phase ?option)))
	)
)

;; HeadphoneActiveWiredBatteryPrimary_CA
(defrule HeadphoneActiveWiredBatteryPrimary_CA
	(declare (auto-focus TRUE))
	?f <- (phase HeadphoneActiveWiredBatteryPrimary_CA)
=>
	(retract ?f)
	(bind ?min 1)
	(bind ?max 2)
	(printout t crlf
		"============================================================" crlf
		" Select Headphone Active Wired Battery Primary CA Options   " crlf
		"============================================================" crlf
		crlf
		"1. Clock Freq > 9KHZ" crlf
		"2. Clock Freq < 9KHZ" crlf
		crlf
		"Please select an option (" ?min "-" ?max "): "
	)
	(bind ?option (readline))
	(if (CheckOptions ?min ?max ?option)
		then (and (printout t crlf "Invalid Options " ?option crlf)
            (assert (phase HeadphoneActiveWiredBatteryPrimary_CA)))
		else (and (bind ?option (ConvertHeadphoneActiveWiredBatteryPrimaryCAMenu (string-to-field ?option)))
            (assert (phase ?option)))
	)
)

;; ConvertHeadphoneActiveWiredBatteryPrimaryCA_FreqH9
(defrule ConvertHeadphoneActiveWiredBatteryPrimaryCA_FreqH9
	(declare (auto-focus TRUE))
	?f <- (phase ConvertHeadphoneActiveWiredBatteryPrimaryCA_FreqH9)
=>
	(retract ?f)
	(printout t crlf
		"Applicable Requirement(s): " crlf
		"-------------------------- " crlf
		"Spectrum Management and Telecommunication (Industry Canada)" crlf
		"Class B test" crlf
		"Applicable Standard(s): " crlf
		"----------------------- " crlf
		"ICES-003:2004" crlf
		crlf
	)
	(assert (stop))
	(assert (quit))
)

;; ConvertHeadphoneActiveWiredBatteryPrimaryCA_FreqL9
(defrule ConvertHeadphoneActiveWiredBatteryPrimaryCA_FreqL9
	(declare (auto-focus TRUE))
	?f <- (phase ConvertHeadphoneActiveWiredBatteryPrimaryCA_FreqL9)
=>
	(retract ?f)
	(bind ?min 1)
	(bind ?max 2)
	(printout t crlf
		"=============================================================================" crlf
		" Select Headphone Active Wired Battery Primary CA ClockFreq < 9KHZ Options   " crlf
		"=============================================================================" crlf
		crlf
		"1. Generated used > 1.705 mHz" crlf
		"2. Generated used < 1.705 mHz" crlf
		crlf
		"Please select an option (" ?min "-" ?max "): "
	)
	(bind ?option (readline))
	(if (CheckOptions ?min ?max ?option)
		then (and (printout t crlf "Invalid Options " ?option crlf)
            (assert (phase ConvertHeadphoneActiveWiredBatteryPrimaryCA_FreqL9)))
		else (and (bind ?option (ConvertHeadphoneActiveWiredBatteryPrimaryCAFreqL9Menu (string-to-field ?option)))
            (assert (phase ?option)))
	)
)

;; ConvertHeadphoneActiveWiredBatteryPrimaryCAFreq9L_GenL17
(defrule ConvertHeadphoneActiveWiredBatteryPrimaryCAFreq9L_GenL17
	(declare (auto-focus TRUE))
	?f <- (phase ConvertHeadphoneActiveWiredBatteryPrimaryCAFreq9L_GenL17)
=>
	(retract ?f)
	(bind ?min 1)
	(bind ?max 2)
	(printout t crlf
		"======================================================================================================" crlf
		" Select Headphone Active Wired Battery Primary CA ClockFreq < 9KHZ Generated used <1.705mHz Options   " crlf
		"======================================================================================================" crlf
		crlf
		"1. Directly connected to mains" crlf
		"2. Not directly connected to mains" crlf
		crlf
		"Please select an option (" ?min "-" ?max "): "
	)
	(bind ?option (readline))
	(if (CheckOptions ?min ?max ?option)
		then (and (printout t crlf "Invalid Options " ?option crlf)
            (assert (phase ConvertHeadphoneActiveWiredBatteryPrimaryCAFreq9L_GenL17)))
		else (and (bind ?option (ConvertHeadphoneActiveWiredBatteryPrimaryCAFreq9LGenL17Menu (string-to-field ?option)))
            (assert (phase ?option)))
	)
)

;; HeadphoneActiveWiredBattery_Secondary
(defrule HeadphoneActiveWiredBattery_Secondary
	(declare (auto-focus TRUE))
	?f <- (phase HeadphoneActiveWiredBattery_Secondary)
=>
	(retract ?f)
	(bind ?min 1)
	(bind ?max 2)
	(printout t crlf
		"==========================================================" crlf
		" Select Headphone Active Wired Battery Secondary Options  " crlf
		"==========================================================" crlf
		crlf
		"1. Nimh (Nickel Metal Hydride)" crlf
		"2. Li Polymer" crlf
		crlf
		"Please select an option (" ?min "-" ?max "): "
	)
	(bind ?option (readline))
	(if (CheckOptions ?min ?max ?option)
		then (and (printout t crlf "Invalid Options " ?option crlf)
            (assert (phase HeadphoneActiveWiredBattery_Secondary)))
		else (and (bind ?option (ConvertHeadphoneActiveWiredBatterySecondaryMenu (string-to-field ?option)))
            (assert (phase ?option)))
	)
)

;; ConvertHeadphoneActiveWiredBatterySecondary_Nimh
(defrule ConvertHeadphoneActiveWiredBatterySecondary_Nimh
	(declare (auto-focus TRUE))
	?f <- (phase ConvertHeadphoneActiveWiredBatterySecondary_Nimh)
=>
	(retract ?f)
	(bind ?min 1)
	(bind ?max 2)
	(printout t crlf
		"===============================================================" crlf
		" Select Headphone Active Wired Battery Secondary Nimh Options  " crlf
		"===============================================================" crlf
		crlf
		"1. External Power Supply" crlf
		"2. USB" crlf
		crlf
		"Please select an option (" ?min "-" ?max "): "
	)
	(bind ?option (readline))
	(if (CheckOptions ?min ?max ?option)
		then (and (printout t crlf "Invalid Options " ?option crlf)
            (assert (phase ConvertHeadphoneActiveWiredBatterySecondary_Nimh)))
		else (and (bind ?option (ConvertHeadphoneActiveWiredBatterySecondaryNimhMenu (string-to-field ?option)))
            (assert (phase ?option)))
	)
)

;; ConvertHeadphoneActiveWiredBatterySecondary_Li
(defrule ConvertHeadphoneActiveWiredBatterySecondary_Li
	(declare (auto-focus TRUE))
	?f <- (phase ConvertHeadphoneActiveWiredBatterySecondary_Li)
=>
	(retract ?f)
	(bind ?min 1)
	(bind ?max 2)
	(printout t crlf
		"=====================================================================" crlf
		" Select Headphone Active Wired Battery Secondary Li Polymer Options  " crlf
		"=====================================================================" crlf
		crlf
		"1. External Power Supply" crlf
		"2. USB" crlf
		crlf
		"Please select an option (" ?min "-" ?max "): "
	)
	(bind ?option (readline))
	(if (CheckOptions ?min ?max ?option)
		then (and (printout t crlf "Invalid Options " ?option crlf)
            (assert (phase ConvertHeadphoneActiveWiredBatterySecondary_Li)))
		else (and (bind ?option (ConvertHeadphoneActiveWiredBatterySecondaryLiMenu (string-to-field ?option)))
            (assert (phase ?option)))
	)
)